/**
 * 
 */
package dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import model.LoaiNhomMonHocM;
import util.DAL;
import util.MyConnectUnit;

public class LoaiNhomMonHocD {
	private MyConnectUnit conn;

	/**
	 * @function constructor LoaiNhomMonHocD
	 * @throws Exception
	 */
	public LoaiNhomMonHocD() throws Exception {
		super();
		this.conn = DAL.getDAL();
	}

	/**
	 * @function get all LoaiNhomMonHoc
	 * @param Condition
	 * @param Limit
	 * @param OrderBy
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> getAll(String Condition, String Limit, String OrderBy)
			throws Exception {
		ArrayList<LoaiNhomMonHocM> ls = new ArrayList<LoaiNhomMonHocM>();
		ResultSet rs = this.conn
				.Select("LOAI_NHOM_MON_HOC", Condition, Limit, OrderBy);
		LoaiNhomMonHocM l = null;
		while (rs.next()) {
			l = new LoaiNhomMonHocM();
			l.setId_loai_nhom_mon_hoc(rs.getInt("id_loai_nhom_mon_hoc"));
			l.setTen(rs.getString("ten"));
			ls.add(l);
		}
		return ls;
	}
	
	/**
	 * @function get all LoaiNhomMonHoc with Condition + Limit
	 * @param Condition
	 * @param Limit
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> getAll(String Condition, String Limit) throws Exception {
		return getAll(Condition, Limit, null);
	}

	/**
	 * @function get all LoaiNhomMonHoc with Condition
	 * @param Condition
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> getAll(String Condition) throws Exception {
		return getAll(Condition, null);
	}

	/**
	 * @function get all LoaiNhomMonHoc no parameter
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> getAll() throws Exception {
		return getAll(null);
	}

	/**
	 * @function search ten LoaiNhomMonHoc
	 * @param ten
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> searchLNMH(String ten) throws Exception {
		ArrayList<LoaiNhomMonHocM> list = getAll("ten LIKE '%" + ten + "%'");
		return list;
	}
	
	/**
	 * @function get all LoaiNhomMonHoc with search + paging
	 * @param from
	 * @param to
	 * @return
	 * @throws Exception
	 */
	public ArrayList<LoaiNhomMonHocM> getLimit(String ten, int from, int to) throws Exception {
		String limit = from + ", " + to;
		ArrayList<LoaiNhomMonHocM> list = getAll("ten LIKE '%" + ten + "%'", limit);
		return list;
	}

	/**
	 * @function insert LoaiNhomMonHoc
	 * @param lnmh
	 * @return
	 * @throws Exception
	 */
	public boolean Insert(LoaiNhomMonHocM lnmh) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("ten", lnmh.getTen());
		return this.conn.Insert("LOAI_NHOM_MON_HOC", map);
	}

	/**
	 * @function update LoaiNhomMonHoc
	 * @param lnmh
	 * @return
	 * @throws Exception
	 */
	public boolean Update(LoaiNhomMonHocM lnmh) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("ten", lnmh.getTen());
		return this.conn.Update("LOAI_NHOM_MON_HOC", map, "id_loai_nhom_mon_hoc = " + lnmh.getId_loai_nhom_mon_hoc());
	}

	/**
	 * @function delete LoaiNhomMonHoc
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public boolean Delete(int id) throws Exception {
		return this.conn.Delete("LOAI_NHOM_MON_HOC", "id_loai_nhom_mon_hoc = " + id);
	}
}